package com.ziven.common.widget.index;

import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @author Ziven
 */
public final class FastScrollBlock {

    public static FastScrollBlock newBlock(@NonNull String indexName) {
        return newBlock(RecyclerView.NO_POSITION, indexName, RecyclerView.NO_POSITION);
    }

    public static FastScrollBlock newBlock(int position, @NonNull String indexName) {
        return newBlock(position, indexName, RecyclerView.NO_POSITION);
    }

    public static FastScrollBlock newBlock(@NonNull String indexName, int index) {
        return newBlock(RecyclerView.NO_POSITION, indexName, index);
    }

    public static FastScrollBlock newBlock(int position, @NonNull String indexName, int index) {
        return new FastScrollBlock(position, indexName, index);
    }

    public int index;
    public int position;
    public final String indexName;

    private FastScrollBlock(int position, @NonNull String indexName, int index) {
        this.index = index;
        this.position = position;
        this.indexName = indexName;
    }

    public boolean isIndex(int index, String name) {
        boolean indexEqual = this.index == index && index != RecyclerView.NO_POSITION;
        return indexEqual || TextUtils.equals(indexName, name);
    }

    @NonNull
    @Override
    public String toString() {
        return "FastScrollBlock{" +
                "index=" + index +
                ", position=" + position +
                ", indexName='" + indexName + '\'' +
                '}';
    }
}
